package com.design.pattern.clone;

/**
 * @author wangyingjie
 * @date
 * @remark 原型模式
 */
public class Shape implements Cloneable {
    private String id;
    private String name;

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    /**
     * 克隆一个新对象
     * @return
     */
    public Shape clone(){
        Shape shape = null;
        try {
            shape= (Shape) super.clone();
        } catch (CloneNotSupportedException e) {
            e.printStackTrace();
        }
        return shape;
    }

//    @Override
//    public String toString() {
//        return "Shape{" +
//                "id='" + id + '\'' +
//                ", name='" + name + '\'' +
//                '}';
//    }

    public static void main(String[] args) {
        Shape shape = new Shape();
        shape.setId("1");
        shape.setName("hahaha ");
        System.out.println("===============>");
        Shape shape2 = shape.clone();
        System.out.println(shape == shape2);
    }
}
